/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ChateoFacadeNI;

import ChateoController.*;
import ChateoNI.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.SocketException;


/**
 *
 * @author adrian
 */
public class FacadeNI {
    private Controller theController;
    private ConnexionUDPServer UDPServer;
    
    public FacadeNI(Controller theController, ConnexionUDPServer UDPServer){
        this.theController=theController;
        this.UDPServer=UDPServer;
    }

    public Controller getTheController() {
        return theController;
    }

    public ConnexionUDPServer getUDPServer() {
        return UDPServer;
    }

    public void setTheController(Controller theController) {
        this.theController = theController;
    }

    public void setUDPServer(ConnexionUDPServer UDPServer) {
        this.UDPServer = UDPServer;
    }
    
    public void incommingHello(String remoteLogin , InetAddress remoteAddr) throws UnknownHostException{
        theController.newUser(remoteLogin, remoteAddr);
    }
    public void outgoingHello(InetAddress addr,String myLogin) throws UnknownHostException, SocketException{
        ConnexionUDPClient sender = new ConnexionUDPClient();
        sender.sendMessage(addr, new Hello(myLogin,false));
    
    }
    public void incommingBye(String remoteLogin, InetAddress remoteAddr) throws UnknownHostException{
        //theController.userLeft(remoteLogin, remoteAddr);
        theController.userLeft();
    }
    public void outgoingBye(InetAddress addr,String myLogin) throws UnknownHostException, SocketException{
        ConnexionUDPClient sender = new ConnexionUDPClient();
        sender.sendMessage(addr, new Bye(myLogin));
    
    }
    public void incommingAck(String remoteLogin , InetAddress remoteAddr) throws UnknownHostException{
        theController.newUser(remoteLogin, remoteAddr);
    }
    public void outgoingAck(InetAddress addr,String myLogin) throws UnknownHostException, SocketException{
        ConnexionUDPClient sender = new ConnexionUDPClient();
        sender.sendMessage(addr, new Hello(myLogin,true));
    }
    
    
}